package com.itheima.tanhua.web;

import com.itheima.tanhua.service.CommentService;
import com.itheima.tanhua.service.MovementService;
import com.itheima.tanhuan.vo.mongo.MovementVo;
import com.itheima.tanhuan.vo.mongo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("movements")
@Slf4j
public class MovementController {
    //业务层对象
    @Autowired
    MovementService movementService;
    @Autowired
    CommentService commentService;

    //发布动态：不能写@RequstBody
    @PostMapping
    public ResponseEntity movements( MovementVo movementVo, MultipartFile imageContent[]){
        System.out.println(1);
        Boolean flage=movementService.movement(movementVo,imageContent);
        return ResponseEntity.ok(null);
    }

    //推荐
//    @GetMapping("all")
    public ResponseEntity all(Long userId,
                       @RequestParam(value = "page",defaultValue = "1") Integer page,
                       @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize){
        log.info("当前页面{}，{}",page,pagesize);
        PageResult pageResult=movementService.all(page,pagesize,userId);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("all")
    public ResponseEntity myMove(Long userId,Integer page,Integer pagesize){
        return movementService.myMove(userId,page,pagesize);
    }

    //好友动态
    @GetMapping
    public ResponseEntity friendMove(int page,int pagesize){
        return movementService.friendMove(page,pagesize);
    }

    /**
     *
     * @param id 动态id
     * @return
     */


    /**
     * 推荐动态
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pr = movementService.findRecommendMovements(page,pagesize);
        return ResponseEntity.ok(pr);
    }



    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String movementId) {
        Integer likeCount = commentService.likeMove(movementId);
        return ResponseEntity.ok(likeCount);
    }

    /**
     * 取消点赞
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String movementId) {
        Integer likeCount = commentService.dislikeMove(movementId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/visitors")
    public ResponseEntity visitor(){
        return ResponseEntity.ok(new Object[]{});
    }

    @GetMapping("{id}")
    public ResponseEntity moveById(@PathVariable("id") Long id){
        log.info("传过来的是{}",id);
        return movementService.movebyid(id);
//        return ResponseEntity.ok(null);
    }
}
